﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

using Rison.Web.Common;
using Rison.BusinessFacade.Entity.Biz;
using Rison.BusinessFacade.Facade.Biz;
using Rison.BusinessFacade.Common;
using Rison.BusinessFacade.Helper;

namespace Rison.Web.view
{
    public partial class SQListView : PageDataViewBase
    {
        protected void Page_Init(object sender, EventArgs e)
        {
            base.dataView = this.gvData;
            base.baseFacade = new InfomationFacade();
            base.hidCurrentPageIndex = this.hidCurPageIndex;
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!this.IsPostBack)
            {
                InitData();
                BindData();
            }
        }

        private string curCategory
        {
            get { return "zxsq"; }
        }


        protected override DataSet GetDataSource()
        {
            InfosReaderFacade facade = new InfosReaderFacade(curCategory);

            string con = "";  //查询条件

            if (drpDepartment.SelectedIndex > 0)
            {
                con = " and source='" + drpDepartment.SelectedItem.Text + " '";
            }
          

            if (drpSQLB.SelectedIndex>0)
            {
                con  = con + " and subtitle='" + drpSQLB.SelectedValue + " '";
            }

            //if (txtPwd.Text.Trim().Length != 0)               
            //{
            //    con = con + " and a.Password='" + txtPwd.Text.Trim() + " '";             
            //}

            return facade.ReadSuqiuList(con);
             
           
        }

        private void InitData()
        {
            DataSourceHelperFacade facade = new DataSourceHelperFacade(InfoCategory.我有诉求);

            DataSet data = facade.GetDepartments();
            this.drpDepartment.DataSource = data.Tables[0].DefaultView;//部门
            this.drpDepartment.DataValueField = "bmid";
            this.drpDepartment.DataTextField = "bmmc";
            this.drpDepartment.DataBind();
            this.drpDepartment.Items.Insert(0, new ListItem("请选择相关部门", "请选择相关部门"));
            if (!string.IsNullOrEmpty(Request.QueryString["depart"]))
            {
                this.drpDepartment.SelectedValue = Request.QueryString["depart"].ToString();
            }
            

            //data = facade.GetSQCategory();
            //this.drpSQLB.DataSource = data.Tables[0].DefaultView;//诉求类别
            //this.drpSQLB.DataValueField = "SQLB";
            //this.drpSQLB.DataTextField = "SQLB";
            //this.drpSQLB.DataBind();
            this.drpSQLB.Items.Clear();
            if (drpSQLB.Items.FindByText("投诉") == null)
                this.drpSQLB.Items.Add(new ListItem("投诉", "投诉"));
            if (drpSQLB.Items.FindByText("意见建议") == null)
                this.drpSQLB.Items.Add(new ListItem("意见建议", "意见建议"));
            if (drpSQLB.Items.FindByText("咨询") == null)
                this.drpSQLB.Items.Add(new ListItem("咨询", "咨询"));
            this.drpSQLB.Items.Insert(0, new ListItem("请选择类别", "请选择类别"));

            if (!string.IsNullOrEmpty(Request.QueryString["type"]))
            {
                this.drpSQLB.SelectedValue = Request.QueryString["type"].ToString();
            }

            data.Dispose(); data = null; facade = null;
        }

        protected void btnSearch_SQ_Click(object sender, EventArgs e)
        {
            BindData();
        }
        
    }
}
